#include<bits/stdc++.h>
using namespace std;
int n,m;
struct line{
	int to,link,id;
}E[600005];
int head[200005],tot;
void addE(int u,int v,int id){
	E[++tot]={v,head[u],id};
	head[u]=tot;
	return;
}
int x,y,q,k;
bool vis[200005],ring[200005],nin[200005];
stack<int> st;
bool flag=0;
void dfs(int now,int f){
	vis[now]=1;
	for(int i=head[now];i;i=E[i].link){
		if(E[i].to!=f){
			if(vis[E[i].to]){
				ring[E[i].id]=1;
				while(!st.empty()&&E[st.top()].to!=E[i].to){
					ring[E[st.top()].id]=1;
					st.pop();
				}
				flag=1;
				return;
			}
			else{
				st.push(i);
				dfs(E[i].to,now);
				if(flag)return;
				st.pop();
			}
		}
	}
	return;
}
queue<int> qq;
vector<int> G[200005];
bool bfs(){
	memset(vis,0,sizeof vis);
	qq.push(1);
	vis[1]=1;
	while(!qq.empty()){
		int u=qq.front();
		qq.pop();
		for(auto p:G[u]){
			if(!vis[p]){
				vis[p]=1;
				qq.push(p);
			}
		}
	}
	for(int i=1;i<=n;i++)if(!vis[i])return 0;
	return 1;
}
int u[200005],v[200005];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	freopen("graph.in","r",stdin);
	freopen("graph.out","w",stdout);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>x>>y;
		addE(x,y,i);
		addE(y,x,i);
		u[i]=x,v[i]=y;
	}
	cin>>q;
	if(n<=3000&&m<=3000&&q<=3000){
		while(q--){
			cin>>k;
			for(int i=1;i<=n;i++)G[i].clear();
			for(int i=1;i<=k;i++)cin>>x,nin[x]=1;
			for(int i=1;i<=m;i++)if(!nin[i])G[u[i]].push_back(v[i]),G[v[i]].push_back(u[i]);else nin[i]=0;
			if(bfs())cout<<"YES\n";
			else cout<<"NO\n";
		}
		return 0;
	}
	dfs(1,0);
	while(q--){
		cin>>k;
		if(k>=2){
			for(int i=1;i<=k;i++)cin>>x;
			cout<<"NO\n";
		}else{
			cin>>x;
			if(ring[x])cout<<"YES\n";
			else cout<<"NO\n";
		}
	}
	return 0;
}